#include "G4RunManager.hh"
#include "BranchingPrimaryGenerator.hh" 
#include "G4GeneralParticleSource.hh"
#include "aPhysicsList.hh"
#include "OurDetectorConstruction.hh"
#include "OurPrimaryGeneratorAction.hh"
#include <iostream>
#include "TTree.h"
#include "TFile.h"
#include "PList.hh"
 
#include "ExN01DetectorConstruction.hh"
#include "ExN01PhysicsList.hh"
#include "ExN01PrimaryGeneratorAction.hh"
#include "G4VModularPhysicsList.hh"
#include "G4VPhysicsConstructor.hh"
#include "LHEP.hh"
#include "QGSP_BIC_HP.hh"


#include "G4UImanager.hh"

#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif

#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif 

int main(int argc,char** argv)
{
	//make instance of run manager
	G4RunManager* rm = new G4RunManager();

	//register the physics list
	rm->SetUserInitialization(new QGSP_BIC_HP());
	//rm->SetUserInitialization(new aPhysicsList() );
	//rm->SetUserInitialization(new ExN01PhysicsList() );
	G4cout << "done setting the physics list \n";

	//register the detector construction
	rm->SetUserInitialization(new OurDetectorConstruction() );
	//rm->SetUserInitialization(new ExN01DetectorConstruction() );
	G4cout << "done setting the detector construction.  \n";

	rm->SetUserAction(new OurPrimaryGeneratorAction());
	//rm->SetUserAction(new ExN01PrimaryGeneratorAction());
	G4cout << "done setting the primary generator action. \n";
	
	G4cout << "initializing run manager \n";
	rm->Initialize();

/*
	G4cout << "starting BeamOn. \n";
	rm->BeamOn(1E5);
	G4cout << "finished BeamOn. \n";

*/

      //----------------
      // Visualization:
      //----------------
      #ifdef G4VIS_USE
         G4cout << "Instantiating Visualization Manager......." << G4endl;
         G4VisManager* visManager = new G4VisExecutive;
         visManager -> Initialize ();
      #endif




 //  Get the pointer to the User Interface manager
  
  G4UImanager * UImanager = G4UImanager::GetUIpointer();  

#ifdef G4UI_USE
      G4UIExecutive * ui = new G4UIExecutive(argc,argv);
#ifdef G4VIS_USE
      UImanager->ApplyCommand("/control/execute vis.mac");     
#endif
      ui->SessionStart();
      delete ui;
#endif
   
	G4cout << "deleting run manager \n";
       #ifdef G4VIS_USE
          delete visManager;
       #endif




	delete rm; 	
	return 0;
}
